package de.fme.tracking;

import java.util.Date;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;


/**
 * iBatis-specific implementation of the DAO for <b>pub_feedback_XXX</b> tables.
 * 
 * @author jploetz
 * @since 4.0b
 */
public class FeedbackDAOImpl implements FeedbackDAO
{
	// defining constants for FEEDBACK METHODS
	private static final String INSERT_FEEDBACK_ENTRY = "fme.feedback.insert_FeedbackEntry";
    private static final String SELECT_FEEDBACK_BY_ID = "fme.feedback.select_FeedbackById";
    private static final String SELECT_FEEDBACK_BY_PUB_EVENT = "fme.feedback.select_FeedbackByPubEvent";
    private static final String SELECT_FEEDBACK_BY_CHANNEL = "fme.feedback.select_FeedbackByChannel";
    private static final String SELECT_FEEDBACK_BY_USER = "fme.feedback.select_FeedbackByUser";
    private static final String DELETE_FEEDBACK_ENTRY = "alfresco.feedback.delete_FeedbackEntry";
    private static final String DELETE_FEEDBACK_ENTRIES_BY_ID = "alfresco.feedback.delete_FeedbackEntriesById";
    
	// defining constants for USER METHODS
    private static final String INSERT_USER_ENTRY = "fme.feedback.insert_UserEntry";
    private static final String INSERT_TYPE_ENTRY = "fme.feedback.insert_TypeEntry";
    
    
    
    // session template
    private SqlSessionTemplate template;
    
    /**
     * {@inheritDoc}
     */
	public int createFeedbackEntry(FeedbackEntity entity) 
	{
		// not sure if the insert method returns the entry ID
        return template.insert(INSERT_FEEDBACK_ENTRY, entity);
	}
    
	/**
     * {@inheritDoc}
     */
	public FeedbackEntity getFeedbackEntry(Long feedbackId) {
		FeedbackQueryParameters parameters = new FeedbackQueryParameters();
		parameters.setFeedbackEnryId(feedbackId);
		return (FeedbackEntity) template.selectOne(SELECT_FEEDBACK_BY_ID, feedbackId);
	}

	/**
     * {@inheritDoc}
     */
	@SuppressWarnings("unchecked")
	public List<FeedbackEntity> getFeedbackByChannelNode(String channelUuid) {
		// TODO SELECT_FEEDBACK_BY_CHANNEL => select all feedbackEntries for channelUuid == abc
		FeedbackQueryParameters parameters = new FeedbackQueryParameters();
		parameters.setPubChannelUuid(channelUuid);
		return (List<FeedbackEntity>) template.selectList(SELECT_FEEDBACK_BY_CHANNEL, parameters);
	}

	/**
     * {@inheritDoc}
     */
	@SuppressWarnings("unchecked")
	public List<FeedbackEntity> getFeedbackByPubEventNode(String pubEventUuid) {
		// TODO SELECT_FEEDBACK_BY_PUB_EVENT => select all feedbackEntries for pubEventUuid == xyz
		FeedbackQueryParameters parameters = new FeedbackQueryParameters();
		parameters.setPubEventUuid(pubEventUuid);
		return (List<FeedbackEntity>) template.selectList(SELECT_FEEDBACK_BY_PUB_EVENT, parameters);
	}

	/**
     * {@inheritDoc}
     */
	public List<FeedbackEntity> getFeedbackByUserId(long userID) {
		// TODO SELECT_FEEDBACK_BY_USER
		return null;
	}

	/**
     * {@inheritDoc}
     */
	public List<FeedbackEntity> getAllFeedbackEntriesFrom(Date fetchDate) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
     * {@inheritDoc}
     */
	public int deleteFeedbackEntries(Long feedbackEntryId) {
		FeedbackQueryParameters parameters = new FeedbackQueryParameters();
		parameters.setFeedbackEnryId(feedbackEntryId);
		return template.delete(DELETE_FEEDBACK_ENTRY, parameters);
	}
	
	/**
	 * Deletes a certain set of feedbacks
	 * @param fromId
	 * @param toId
	 * @return
	 */
	public int deleteFeedbackEntries(Long fromId, Long toId) {
		FeedbackQueryParameters parameters = new FeedbackQueryParameters();
		parameters.setFromEntryId(fromId);
		parameters.setToEntryId(toId);
		return template.delete(DELETE_FEEDBACK_ENTRIES_BY_ID, parameters);
	}

	/**
     * {@inheritDoc}
     */
	public int createUserEntry(UserEntity user) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
     * {@inheritDoc}
     */
	public UserEntity getUserById(long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
     * {@inheritDoc}
     */
	public UserEntity getUserByFeedbackId(long feedbackId) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
     * {@inheritDoc}
     */
	public int deleteUserById(Long userId) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
     * {@inheritDoc}
     */
	public int deleteUsersByUserIds(List<Long> userEntryIds) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
     * {@inheritDoc}
     */
	public int deleteUsersByFeedbackIds(List<Long> feedbackEntryIds) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
     * {@inheritDoc}
     */
	public int createFeedbackTypeEntry(TypeEntity type) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
     * {@inheritDoc}
     */
	public int deleteFeedbackTypeEntry(TypeEntity type) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	/**
     * SETS THE SESSION TEMPLATE
     * @param sqlSessionTemplate
     */
    public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) 
    {
        this.template = sqlSessionTemplate;
    }
}

